package cn.edu.zucc.anoDao;
import cn.edu.zucc.entity.Stu;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Map;

/**
 * @description stuMapper
 * @author zhengkai.blog.csdn.net
 * @date 2022-04-15
 */
@Mapper
@Repository
public interface StuMapper {

//    @Select("select * from stu where stu_id=#{id}")
//    public Stu getById(Integer id);

//    @Options(useGeneratedKeys=true,keyProperty="stuId")
//    @Insert("insert into stu" +
//        " (id,name,stu_num,sex,id_num,email)" +
//        " values(id,name,stuNum,sex,idNum,email)")
//    public Integer insert(Stu stu);

//    @Options(useGeneratedKeys=true,keyProperty="id")
//    @Insert("insert into stu" +
//            " (id,name,stu_num,sex,id_num,email)" +
//            " values(id,name,stuNum,sex,idNum,email)")
//    public Integer insert(Stu stu);

    @Options(useGeneratedKeys=true,keyProperty="id")
    @Insert("insert into stu" +
            " (id,name,stu_num,sex,id_num,email)" +
            " values(#{id},#{name},#{stuNum},#{sex},#{idNum},#{email})")
    public Integer insert(Stu stu);


//    @Delete(value = "delete from stu where stu_id=#{stuId}")
////    boolean delete(Integer id);
//    Integer delete(Integer id);

    //这种假如表是stu 那么id是 id, 两种选择都放着，想用某一种 只要把另外一种注释就行了
    @Select("select * from stu where id=#{id}")
    public Stu getById(Integer id);

    @Delete(value = "delete from stu where id=#{id}")
    Integer delete(Integer id);

//    @Update(value = "update stu set "
//
//        +" name=#{name},"
//        +" stu_num=#{stuNum},"
//        +" sex=#{sex},"
//        +" id_num=#{idNum},"
//        +" email=#{email}"
//        +" where stu_id=#{stuId} ")
////    boolean update(Stu stu);
//    Integer update(Stu stu);
@Update(value = "update stu set "

        +" name=#{name},"
        +" stu_num=#{stuNum},"
        +" sex=#{sex},"
        +" id_num=#{idNum},"
        +" email=#{email}"
        +" where id=#{id} ")
Integer update(Stu stu);

    @Results(value = {
        @Result(property = "id", column = "id"),
        @Result(property = "name", column = "name"),
        @Result(property = "stuNum", column = "stu_num"),
        @Result(property = "sex", column = "sex"),
        @Result(property = "idNum", column = "id_num"),
        @Result(property = "email", column = "email")
    })
    @Select(value = "select * from stu where stu_id=#{queryParam}")
    Stu selectOne(String queryParam);

    @Results(value = {
        @Result(property = "id", column = "id"),
        @Result(property = "name", column = "name"),
        @Result(property = "stuNum", column = "stu_num"),
        @Result(property = "sex", column = "sex"),
        @Result(property = "idNum", column = "id_num"),
        @Result(property = "email", column = "email")
    })
    @Select(value = "select * from stu where "
        +" id=#{id} or "
        +" name=#{name} or "
        +" stu_num=#{stuNum} or "
        +" sex=#{sex} or "
        +" id_num=#{idNum} or "
        +" email=#{email}"
    )
    List<Stu> selectList(Stu stu);

    @Results(value = {
            @Result(property = "id", column = "id"),
            @Result(property = "name", column = "name"),
            @Result(property = "stuNum", column = "stu_num"),
            @Result(property = "sex", column = "sex"),
            @Result(property = "idNum", column = "id_num"),
            @Result(property = "email", column = "email")
    })
    @Select(value = "select * from stu  "
            +" LIMIT #{offset} , #{pageSize}"
    )
//    List<Map<String,Object>> pageList(int offset, int pageSize);
    List<Stu> pageList(int offset, int pageSize);

//    @Select(value = "select * from stu where "
//            +" id=#{id} or "
//            +" name=#{name} or "
//            +" stu_num=#{stuNum} or "
//            +" sex=#{sex} or "
//            +" id_num=#{idNum} or "
//            +" email=#{email}"
//            +" LIMIT #{offset} , #{pageSize}"
//    )
//    List<Stu> pageList(int offset, int pageSize);

    @Select(value = "SELECT count(1)\n" +
            "        FROM stu"
    )
   Integer pageListCount(int offset, int pageSize);
}
